﻿Imports System.Xml

Namespace Spreads
	Public Class FlattenerPreference

		Property LineArtAndTextResolution As Double

		Property GradientAndMeshResolution As Double

		Property ClipComplexRegions As Boolean

		Property ConvertAllStrokesToOutlines As Boolean

		Property ConvertAllTextToOutlines As Boolean

		Private Property RasterVectorBalance As RasterVectorBalance

		Public Shared Function ReadXml(reader As XmlReader) As FlattenerPreference
			Dim fp As New FlattenerPreference()

			If reader.HasAttributes Then
				fp.LineArtAndTextResolution = Parser.ParseDouble(reader.GetAttribute("LineArtAndTextResolution"))
				fp.GradientAndMeshResolution = Parser.ParseDouble(reader.GetAttribute("GradientAndMeshResolution"))
				fp.ClipComplexRegions = CBool(reader.GetAttribute("ClipComplexRegions"))
				fp.ConvertAllStrokesToOutlines = CBool(reader.GetAttribute("ConvertAllStrokesToOutlines"))
				fp.ConvertAllTextToOutlines = CBool(reader.GetAttribute("ConvertAllTextToOutlines"))
			End If

			If Not reader.IsEmptyElement Then
				While reader.Read()
					Select Case reader.Name
						Case "Properties"
							While reader.Read()
								Select Case reader.Name
									Case "RasterVectorBalance"
										fp.RasterVectorBalance = RasterVectorBalance.ReadXml(reader)
									Case Else
										If reader.NodeType = XmlNodeType.Element Then
											Debug.WriteLine("Unrecognized element: {0} in element: {1}", reader.Name, "FlattenerPreference - Properties")
										End If
								End Select
								If reader.Name = "Properties" And reader.NodeType = XmlNodeType.EndElement Then Exit While
							End While
						Case Else
							If reader.NodeType = XmlNodeType.Element Then
								Debug.WriteLine("Unrecognized element: {0} in element: {1}", reader.Name, "FlattenerPreference")
							End If
					End Select
					If reader.Name = "FlattenerPreference" And reader.NodeType = XmlNodeType.EndElement Then Exit While
				End While
			End If

			Return fp
		End Function
	End Class
End Namespace